# -*- coding: utf-8 -*-
# time: 2025/4/9 14:52
# file: llm_ts.py
# author: hanson
from langchain_community.llms import HuggingFacePipeline
from transformers import pipeline
from langchain.memory import ConversationBufferMemory

# 创建带记忆的链
memory = ConversationBufferMemory(memory_key="chat_history")
conversation = LLMChain(
    llm=llm,
    prompt=PromptTemplate.from_template(
        """当前对话历史：
        {chat_history}
        新问题：{question}
        回答："""
    ),
    memory=memory,
    verbose=True
)

# 多轮对话测试
conversation.invoke({"question": "什么是神经网络？"})
conversation.invoke({"question": "它与深度学习有什么关系？"})